package battle.battleFightData
{
	import flash.net.getClassByAlias;
	import flash.utils.getDefinitionByName;

	/*
	 *此类用于加载战斗动画的motion xml 文件 
	*/
	public class XMLDataLoader implements XMLSerializable
	{
		private var _battleFrames:Vector.<BattleData>;
		//动作时间序列，两个为一对
		private var _moveTimeArray:Array;
		
		public function XMLDataLoader()
		{
			
		}
		
		public function get moveTimeArray():Array
		{
			return _moveTimeArray;
		}

		public function set moveTimeArray(value:Array):void
		{
			_moveTimeArray = value;
		}

		public function get battleFrames():Vector.<BattleData>
		{
			return _battleFrames;
		}

		public function set battleFrames(value:Vector.<BattleData>):void
		{
			_battleFrames = value;
		}

		public function toXml():XML
		{
			return null;
		}
		
		public function fromXml(xml:XML):void
		{
			this._moveTimeArray = new Array();
			this._battleFrames = new Vector.<BattleData>();
			
			if(!xml.hasOwnProperty("moveTime"))
				throw new Error("xml中不存在movetime元素");
			for each(var span:XML in xml.moveTime[0].timeSpan)
			{
				_moveTimeArray.push(span.@start);
				_moveTimeArray.push(span.@end);
			}
			
			//获取里面的frame
			if(!xml.hasOwnProperty("frame"))
				throw new Error("xml文件中不存在frame元素");
			for each(var frame:XML in xml.frame)
			{
				var data:BattleData = new BattleData();
				data.fromXml(frame);
				this._battleFrames.push(data);
			}
		}
	}
}